<script type="text/javascript"><!--//--><![CDATA[//><!--

	var grid_reload = function(){
		$('#datagrid').datagrid('reload', $('#fm_search').serializeObject());
	};

	$(document).ready(function() {
		// Setup Datagrid
		$('#datagrid').datagrid({  
			url:gs_path+'/'+controller+'/getdata', 
			queryParams: $('#fm_search').serializeObject(),
			height:340,
			pagination:true,
			columns:[[
				{ field : 'ck', checkbox:true, width: 40, align: 'center', rowspan:2},				
				{ field : 'kode_sewa', title : 'Kode Sewa', width:100, sortable:true, rowspan:2},
				{ field : 'tanggal_sewa', title : 'Tanggal sewa', width:100, sortable:true, rowspan:2},
				{ field : 'kode_mitra', title : 'Kode Mitra', width:100, sortable:true, rowspan:2},
				{ field : 'kode_tempat', title : 'Kode Tempat', width:100, sortable:true, rowspan:2},
				{ field : 'masa_kontrak', title : 'Masa Kontrak', width:120, sortable:true, rowspan:2},
				{ field : 'biaya_kontrak', title : 'Biaya Kontrak', width:120, sortable:true, rowspan:2},
				{ field : 'keterangan', title : 'Keterangan', width:150, sortable:true, rowspan:2},
				]
			]
		});
		
		// Setup Form
		$('#form_master').setupForm([
			{ name: 'kode_sewa', type: 'text', size: 'medium', maxlength: 20, noempty:true },
			{ name: 'tanggal_sewa', type: 'date', size: 'short', maxlength: 20, noempty:true },
			{ name: 'kode_mitra', type: 'lov', size: 'short',
				onClearButton:function(){
					$(this).setval(''); 
					$('#nama_mitra').setval(''); 
				},
				onActionButton:function(){ 
					LOVMitra({ onSelect:function(row){ 
						$('#kode_mitra').setval(row.kode_mitra); 
						$('#nama_mitra').setval(row.nama_mitra); 
					} }); 
				}
			},
			{ name: 'nama_mitra', type: 'text', size: 'medium', maxlength: 20, readonly:true },
			{ name: 'kode_tempat', type: 'lov', size: 'short',
				onClearButton:function(){
					$(this).setval(''); 
					$('#nama_tempat').setval(''); 
				},
				onActionButton:function(){ 
					LOVTempat({ onSelect:function(row){ 
						$('#kode_tempat').setval(row.kode_tempat); 
						$('#nama_tempat').setval(row.nama_tempat); 
					} }); 
				}
			},
			{ name: 'nama_tempat', type: 'text', size: 'medium', maxlength: 20, readonly:true },
			{ name: 'masa_kontrak', type: 'text', size: 'long', maxlength: 15, noempty:true },
			{ name: 'biaya_kontrak', type: 'text', size: 'long', maxlength: 15, noempty:true },
			{ name: 'keterangan', type: 'text', size: 'long', maxlength: 225, noempty:true },
		]);
		
		
		// Create Dialog
		$('#dialog_container').dialog({
			closed:true,
			modal:true,
			title: '_',
			width:600,
			height:400,
			buttons:[{
				text:'Save',
				iconCls:'icon-save',
				handler:function(){
					$('#form_master').submitForm('/'+controller+'/ajax_post', { onComplete : function(){ $('#dialog_container').dialog('close'); $('#datagrid').datagrid('reload'); }} );
				}
			},{
				text:'Close',
				iconCls:'icon-cancel',
				handler:function(){
					$('#dialog_container').dialog('close');
				}
			}]
		});
		
		
		// Set Action Button
		var buttons = [ { label: 'Add', icon: 'add', onclick: function() {
							resetError();
							$('#dialog_container').dialog('open');
							$('#form_master').data('mode', 'create');
							$('#form_master').parent().parent().parent().prev().find('.panel-title').html('New Sewa');
							$('#kode_sewa').readonly(false);
							$('#kode_sewa, #tanggal_sewa, #kode_mitra, #kode_tempat, #masa_kontrak, #biaya_kontrak, #keterangan').val('');
							$('#kode_sewa').focus();
						} },
						{ label: 'Edit', icon: 'edit', onclick: function() {
							var oSel=$('#datagrid').datagrid('getSelected'); 
							if(oSel==null){ alert('Please select row!'); }
							else{ 
								resetError();
								$('#dialog_container').dialog('open'); 
								$('#form_master').data('mode', 'edit');
								$('#form_master').parent().parent().parent().prev().find('.panel-title').html('Edit Sewa');
								$('#kode_sewa').readonly();
								jsonToForm(oSel); $('#kode_sewa').focus();
							} 
						} },
						{label: 'Delete', icon: 'delete', onclick: function() { 
							var oSel = $('#datagrid').datagrid('getSelected'); 
							if (oSel == null) { 
								$.messager.alert('&nbsp;', gs_msg_row_unselected, 'warning'); 
							} else { 
								deleteData(['kode_sewa']);
							} 
						}}];
		setAction(buttons);
		
		
		$('#fm_search').focusFirst();
	});
//--><!]]></script>

<div id="tb" style="padding:5px;height:auto">
    <div>
        <form id="fm_search" onsubmit="grid_reload(); return false;">
        	<table class="tb_form" style="margin-bottom:0px">
            <tr>
            	<td width="100">Keyword</td>
                <td><input type="text" id="keyword" name="keyword" class="textfield medium" />
                	<a href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="grid_reload(); return false;">Search</a>
                </td>
            </tr>
            </table>
        </form>
    </div>
</div>
<div id="datagrid" toolbar="#tb"></div>


<div id="dialog_container" style="padding:5px;width:600px;height:250px;">
	<form id="form_master">
    <table class="tb_form" style="width:100%;" cellpadding="0" cellspacing="0">
    <tr>
        <td class="label" style="width:150px">Kode Sewa</td>
        <td colspan="2"><input id="kode_sewa" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Tanggal Sewa</td>
        <td colspan="2"><input id="tanggal_sewa" /></td>
    </tr>
    
        <td class="label" style="width:150px">Kode Mitra</td>
        <td colspan="2"><input id="kode_mitra" /> <input id="nama_mitra" /></td>     
    </tr>     
	<tr>
        <td class="label" style="width:150px">Kode Tempat</td>
        <td colspan="2"><input id="kode_tempat" /><input id="nama_tempat" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Masa Kontrak</td>
        <td colspan="2"><input id="masa_kontrak" /></td>
    </tr> 
        <td class="label" style="width:150px">Biaya Kontrak</td>
        <td colspan="2"><input id="biaya_kontrak" /></td>
    </tr>
    <tr>
        <td class="label" style="width:150px">Keterangan</td>
        <td colspan="2"><textarea rows="5" name="keterangan" id="keterangan" /></td>
    </tr>
    </table>
	</form>
</div>